package com.example.service;

import com.example.entity.Product;
import com.example.mapper.ProductMapper;
import com.example.vo.ProductVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductService {

    @Resource
    private ProductMapper productMapper;

    public List<ProductVO> selectAll(ProductVO product) {
        return productMapper.selectAll(product);
    }

    public ProductVO selectById(Integer id) {
        return productMapper.selectById(id);
    }


    public PageInfo<ProductVO> selectPage(ProductVO product, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ProductVO> list = productMapper.selectAll(product);
        return PageInfo.of(list);
    }
    public PageInfo<ProductVO> selectPageByMerchant(Integer sId,ProductVO product, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ProductVO> list = productMapper.selectAllByMerchant(sId,product);
        return PageInfo.of(list);
    }

    public void add(Product product) {
        product.setState(1);
        productMapper.insert(product);
    }

    public void updateById(Product product) {
        productMapper.updateById(product);
    }

    public void deleteById(Integer id) {
        productMapper.deleteById(id);
    }


    public void freezeById(Integer id) {
        productMapper.freezeById(id);
    }

    public List<ProductVO> selectHistory(Integer sId) {
        return productMapper.selectHistory(sId);
    }

    public List<ProductVO> listedProduct() {
        return productMapper.listedProduct();
    }
    public int getproid(Integer id) {
        return productMapper.getproid(id);
    }
}
